<template>
  <div class="parcel" ref="parcel">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BetterScroll from "better-scroll";
export default {
  data() {
    return {
      bs: null,
    };
  },
  props: {
    probeType: {
      type: Number,
      default: 0,
    },
    pullUpLoad: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    scroll(x, y, time = 300) {
      this.bs && this.bs.scrollTo(x, y, time);
    },
    refresh() {
      this.bs && this.bs.refresh();
    },
    getScrollY() {
      return this.bs ? this.bs.y : 0
    }
  },
  mounted() {
    // console.log(this.$refs.parcel);
    // 实例化better-scroll里面的构造函数
    this.bs = new BetterScroll(this.$refs.parcel, {
      //0和1都是不监测scroll事件的，2是只监测鼠标在parcel的盒子里的拖动事件，3是都监测，鼠标和盒子的滚动
      probeType: this.probeType,
      //开启上拉到底部时触发的事件
      pullUpLoad: this.pullUpLoad,
      // 开启盒子内部的单击默认事件
      click: true,
    });
    // 触发滚动时的事件
    this.bs.on("scroll", (position) => {
      this.$emit("scrollClick", position.y);
    });
    // 上拉至底部时的事件
    this.bs.on("pullingUp", () => {
      this.$emit("pullingUp");
    });
  },
};
</script>

<style scoped>
</style>